import { App, defineAsyncComponent } from 'vue'

// 自动加载 examples 下所有 .vue 文件
// @ts-ignore
const modules = import.meta.glob('../../examples/**/*.vue')

export function enhanceAppWithDemos(app: App) {
    Object.entries(modules).forEach(([path, loader]) => {
        const match = path.match(/examples\/(.+)\.vue$/)
        if (!match) return
        const name = 'dev-' + match[1].replace(/\//g, '-')
        // @ts-ignore
        app.component(name, defineAsyncComponent(loader))
    })
}
